<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/jsp/commons/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/jsp/commons/cssinclude.jsp"></jsp:include>
<jsp:include page="/jsp/commons/scriptinclude.jsp"></jsp:include>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>晶品科技信息管理系统-配置管理</title>

</head>
<body>
	 
	<div class="mainbox">

		<div class="main_content">
			 
			<div class="main_right">
				<div class="main_rightbox">
					<div class="ec_crumb_kc">
						<span><a class="icon_up" href="#">上一页</a><a
							class="icon_index" href="${ctx }">首页</a></span>当前位置：配置管理&nbsp;&gt;&nbsp;<em>字典配置</em>
					</div>
				</div>
				<!--品牌基本信息 begin-->
				<div class="ty_border">
					<div class="ty_head">
						<span class="icon4"></span>字典基本信息
					</div>
					<div class="sx_body">
						<form  action="${ctx}/syspara/sysparaAction!editSyspara.action"
							id="sysparaForm" method="post">
							<input type="hidden" id="hbActionType" value="${actionType}" />
							<input type="hidden" id="id" value="${syspara.id}" />
							<dl class="clearfix">
								<dt style="display: none;">字典基本信息</dt>

								<dd>
									<label class="name">字典名称：</label><span class="toname"><input
										name="syspara.name" type="text" value="${syspara.name}"
										id="sysparaName" title="searchfield" class="winput3" /></span>
									<div class="fl">
										<em id="sysparaNameTip"></em>
									</div>
								</dd>
								<dd>
									<label class="name">字典编码：</label><span class="toname"><input
										name="syspara.code" type="text" value="${ syspara.code}"
										id="sysparaCode" title="searchfield" class="winput3" /></span>
									<div class="fl">
										<em id="sysparaCodeTip"></em>
									</div>
								</dd>
								<dd>
									<label class="name">字典类型：</label><span class="toname"><input
										name="syspara.type" type="text" value="${syspara.type}"
										id="sysparaType" title="searchfield" class="winput3" /></span>
									<div class="fl">
										<em id="sysparaTypeTip"></em>
									</div>
								</dd>
								<dd>
									<label class="name">字典值：</label><span class="toname"><input
										name="syspara.value" type="text" value="${ syspara.value}"
										id="sysparaValue" title="searchfield" class="winput3" /></span>
									<div class="fl">
										<em id="sysparaValueTip"></em>
									</div>
								</dd>
								<dd>
									<input type="hidden" id="sysparaState"
										value="${syspara.state}"> <label class="name">状
										态：</label><span class="toname"> <input type="radio" value="1"
										checked="checked" name="syspara.state" id="tonamera1"
										class="radioclass" /> <label for="tonamera1">生效</label> <input
										type="radio" value="0" name="syspara.state" id="tonamera1"
										class="radioclass" /> <label for="tonamera2">失效</label>
									</span>
								</dd>
								<dd>
									<label class="name">排序：</label><span class="toname"><input
										name="syspara.sort" type="text"  value="${ syspara.sort}"
										id="sysparaSort" title="searchfield" class="winput3" /></span>
									<div class="fl">
										<em id="sysparaSortTip"></em>
									</div>
								</dd>
							</dl>

							<div class="baocun">
								<button class="gybg saveBtn" id="btnSave" type="button">保存</button>
								<button class="gybg qxBtn" id='btnQuit' type="button">取消</button>
							</div>
						</form>
						<div class="clear"></div>
					</div>
					<!--保存取消 begin-->

				</div>

			</div>
		</div>

	</div>

	<!-- JQ -->

	<script type="text/javascript">
	
		//根据状态为来决定是增加还是修改
        $("#btnSave").click(function(){
        	var strActionType=$("#hbActionType").val();
        	if(strActionType!=""){
        		if(strActionType==0){
        			//新增操作
        			//验证编码
        			var vCode=$("#sysparaCode").val();
        			if(vCode==""){
	        			$("#sysparaCodeTip").html(setPrompt("onError","字典编码不能为空，亲输入","${ctx}"));
        			    $("#sysparaForm").focus();
        			}else{
        				if(codeValidator( $("#sysparaCode").val(),"N")){
		        		    $("#sysparaForm").attr("action","${ctx}/syspara/sysparaAction!addSyspara.action");
		        		    $("#sysparaForm").submit();
        				}else{
        					$("#sysparaForm").focus();
        				}
        			}
        		}else if(strActionType==1){
        			//修改操作
        			$("#sysparaForm").attr("action","${ctx}/syspara/sysparaAction!updateSyspara.action");
        			$("#sysparaForm").submit();
        		}else{
        			alert("系统错误，请联系系统管理员！");
        		}
        	}else{
    			alert("系统错误，请联系系统管理员！");
    		}
        });
		
        /**
         * 验证编码
         * @param code 编码
         * @param flag 是否异步
         */
        function codeValidator(code,flag){
        	var result=false;
        	//异步验证
        	if(flag=="Y"){
        		$.post(
	    			    "${ctx}/syspara/sysparaAction!codeValidator.action", 
	    				{random:Math.random(),"syspara.code":code}, 
	    				function(data){
	    					   var jsonData = $.parseJSON(data); 
	    					    if(jsonData.flag=="success"){
	    					    	$("#sysparaCodeTip").html(setPrompt("onSuccess",jsonData.data,"${ctx}"));
	    					    	result=true;
	    					    }else{
	    					    	$("#sysparaCodeTip").html(setPrompt("onError",jsonData.errorMsg,"${ctx}"));
	    					    }
	    			         }); 
        	}else{
        		//同步验证
        		var url = "${ctx}/syspara/sysparaAction!codeValidator.action";
        		var params = {"random":Math.random(),"syspara.code":code};
        		$.ajax({
        			url:url,
        			type:'post',
        			data:params, 
        			async:false,
        			dataType:'json',
        			success:function (jsonData) {
        				//var jsonData = $.parseJSON(data); 
        				if(jsonData.flag=="success"){
 					    	$("#sysparaCodeTip").html(setPrompt("onSuccess",jsonData.data,"${ctx}"));
 					    	result=true;
 					    }else{
 					    	$("#sysparaCodeTip").html(setPrompt("onError",jsonData.errorMsg,"${ctx}"));
 					    }
        			},error : function() {
        				alert("系统错误");
        				queryCategory();
        			}	
        		}); 
        	}
        	return result;
        } 
		
        /**
        *绑定值改变事件
        */
        $("#sysparaCode").change(function(){
        	$("#sysparaCodeTip").html(setPrompt("onLoad","正在验证数据，请稍等","${ctx}"));
        	codeValidator( $("#sysparaCode").val(),"Y");
        });
		
		$(".ctnGdpOptionPanel li").hover(function() {
			$(this).addClass("hover");
		}, function() {
			$(this).removeClass("hover");
		});
		$(".arrowname").click(function() {
			var domUl = $(this).parent().find(".ctnGdpOptionPanelMask");
			var domArrow = $(this).find("span.arrowdown");
			if (domArrow.hasClass("arrowUp")) {
				domArrow.removeClass("arrowUp");
				domUl.show();
			} else {
				domArrow.addClass("arrowUp");
				domUl.hide();
			}
		});
		
		//取消事件
		$("#btnQuit").click(function(){
			art.dialog.confirm('你确认放弃页面操作，返回列表？', function(){
				location.href ="${ctx}/syspara/sysparaAction!initSyspara.action";
			}, function(){
			     
			});
		});
	</script>
</body>
</html>